Page({
  data: {
    repairList: [],
    isShow: false,
    params: {
      current: 1,
      pageSize: 3,
    },
    showText: false,
    loading: false,
  },
  onLoad() {
    this.getrepairList()
  },
  // 获取保修列表
  async getrepairList() {
    if (this.data.params.current === 1) this.copy = this.data
    console.log(this.copy)
    wx.showLoading()
    const {
      code,
      data: { rows: repairList, total },
    } = await wx.http.get('/repair', this.data.params)
    if (code !== 10000) return wx.utils.toast()
    this.data.repairList.push(...repairList)
    this.setData({
      total,
      repairList: this.data.repairList,
      isShow: repairList.length === 0,
    })
    // 获取下一页数据
    wx.hideLoading()
  },
  goDetail(e) {
    wx.navigateTo({
      url: '/repair_pkg/pages/detail/index?id=' + e.mark.id,
    })
  },

  // 下拉刷新
  refreshH() {
    // 将data设置为初始值
    this.setData(this.copy)
    // this.getrepairList()
  },
  addRepair() {
    wx.navigateTo({
      url: '/repair_pkg/pages/form/index',
    })
  },
  // 上拉触底事件
  DownGG() {
    if (this.data.repairList.length < this.data.total) {
      this.setData({
        params: {
          current: ++this.data.params.current,
          pageSize: 3,
        },
      })
      this.getrepairList()
    } else {
      this.setData({
        showText: true,
      })
    }
  },
})
